home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
LANG
/
C
/
LIB
/
UNIXLIB37B
/
!UnixLib37
/
src
/
stdio
/
c
/
flsbuf
< prev
next >
Wrap
Text File
|
1996-11-09
|
2KB
|
77 lines
/****************************************************************************
*
* $Source: /unixb/home/unixlib/source/unixlib37/src/stdio/c/RCS/flsbuf,v $
* $Date: 1996/05/06 09:01:34 $
* $Revision: 1.2 $
* $State: Rel $
* $Author: unixlib $
*
* $Log: flsbuf,v $
* Revision 1.2 1996/05/06 09:01:34 unixlib
* Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
* Saved for 3.7a release.
*
* Revision 1.1 1996/04/19 21:32:42 simon
* Initial revision
*
***************************************************************************/
static const char rcs_id[] = "$Id: flsbuf,v 1.2 1996/05/06 09:01:34 unixlib Rel $";
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
__STDIOLIB__
/* __flsbuf(-1,f) flushes output without adding c */
int
__flsbuf (register int c, register FILE * f)
{
register int n, b, g = f->flag;
register unsigned char *a, *p;
if ((g & (_IOWRITE | _IOERR)) != _IOWRITE)
return (-1);
b = (g & _IONBF) ? 1 : f->bufsiz;
if (!(a = f->o_base))
{
if (!(a = f->o_base = malloc (b)))
{
f->flag = g | _IOERR;
return (-1);
}
if (b > 1 && c >= 0 && !(c == '\n' && (g & _IOLBF)))
{
f->o_cnt = b - 1;
f->o_ptr = a + 1;
return (*a = c);
}
p = f->o_ptr = a;
}
else
p = f->o_ptr;
if (c >= 0)
*p++ = c;
n = p - a;
if (n > 0)
if (write (f->fd, a, n) < n)
{
f->flag = g | _IOERR;
return (-1);
}
f->pos += n;
f->o_cnt = b;
f->o_ptr = a;
return ((c >= 0) ? c : 0);
}